<?php
/**
 *
 * Author: Zeon
 * Date: 2018/3/23
 * Time: 13:53
 * Created by PanxSoft.
 */
namespace App\Services\Utils;

use SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;

class SimpleQrCode
{
    /**
     * @param string $content
     * @param string $type
     * @return string - 图片二进制字符串，可直接做为图片的进制数据返回前端
     */
    public static function toImage(
        string $content,
        string $type = 'png'
    ): string
    {
        $qr_code = (new BaconQrCodeGenerator)
            ->encoding('UTF-8')
            ->format($type)
            ->size(300)
            ->margin(0)
            ->backgroundColor(255, 255, 255)
            ->generate($content);

        return $qr_code;
    }
}